#include "stdafx.h"
#include "WMPPlusHook.h"
#include "..\WMP\Common.h"
#include "WMPPlusCore.h"
#include "WMPPlusHookData.h"

#pragma unmanaged

IWMPPlusHook* Host;

const GUID WMPPlus_CLSID = {0xA5D0DDBE, 0x4316, 0x4E8F, 0xA6, 0x6E, 0xDC, 0xD5, 0xF9, 0xD8, 0x70, 0xB4};

void WINAPI WMPInitialize3(HMODULE module, HMODULE instance, int majorVersion, int minorVersion, IMPORT_LIBRARY lib) {
	HRESULT hr;
	CreateTextBuffer(textBuffer);

	if (FAILED(hr=CoInitializeEx(NULL, COINIT_APARTMENTTHREADED))) {
		_sntprintf(textBuffer, textBufferLength, _T("CoInitializeEx failed: %lX"), hr);
		OutputDebugString(textBuffer);
		return;
	}
	if (FAILED(hr=CoCreateInstance(WMPPlus_CLSID, NULL, CLSCTX_INPROC_SERVER, __uuidof(IWMPPlusHook), (void**)&Host))) {
		_sntprintf(textBuffer, textBufferLength, _T("CoCreateInstance(WMPPlus_CLSID, IWMPPlusHook) failed: %lX"), hr);
		OutputDebugString(textBuffer);
		return;
	}
	Core->Hook->MajorVersion = majorVersion;
	Core->Hook->MinorVersion = minorVersion;
	Core->Hook->Libraries = lib;
	Host->Initialize3(module, instance, majorVersion, minorVersion, lib);
}

void WINAPI WMPUninitialize() {
	if (Host) {
		Host->Uninitialize();
		Host->Release();
	}
	Host = NULL;
}

